<template>
	<view class="normal-login-container">
		<swiper indicator-dots autoplay>
			<swiper-item v-for="(item, index) in imgList" :key="index">
				<image :src="item" class="slide-image"></image>
			</swiper-item>
		</swiper>



		<view v-for="(item,index) in listData" :key="item.id">
			<uni-card padding="0" spacing="0">
				<template v-slot:cover>
					<view class="custom-cover">
						<table>
							<tr>
								<th align="center">
									<image :src="item.img" class="cover-image" mode="aspectFill">
									</image>
								</th>
								<th><text
										style="font-size: 22rpx;font-weight:lighter;text-align: left;">{{item.title_en}}</text>
								</th>
							</tr>
							<tr>
								<th colspan=2 style="text-align: right;">
									<uni-link :href="item.url" showUnderLine="false"><button
											class="mini-btn" type="warn"
											size="mini">buy</button></uni-link>
								</th>
							</tr>
						</table>
					</view>
				</template>
			</uni-card>
		</view>


		<uni-card title="about" extra="more">
			<uni-icons type="email" size="30"></uni-icons><text>mxkjtech@gmail.com</text>
			<uni-icons type="weixin" size="30"></uni-icons><text>yushuaijinxiao</text><br />
			<uni-icons type="weixin" size="30"></uni-icons><text>yushuaijinxiao</text>
		</uni-card>


	</view>
</template>

<script>
	import {
		getCodeImg,
		getListData
	} from '@/api/login'

	export default {
		data() {
			return {
				codeUrl: "",
				captchaEnabled: true,
				// 用户注册开关
				register: false,
				globalConfig: getApp().globalData.config,
				loginForm: {
					username: "admin",
					password: "admin123",
					code: "",
					uuid: ''
				},
				listData: [],
				imgList: [
					'https://www.ttddb.com/img/b-1.jpg',
					'https://www.ttddb.com/img/b-2.jpg'
				]
			}
		},
		created() {
			// this.getCode()
			this.getData();
		},
		methods: {
			// 用户注册
			handleUserRegister() {
				this.$tab.redirectTo(`/pages/register`)
			},
			// 隐私协议
			handlePrivacy() {
				let site = this.globalConfig.appInfo.agreements[0]
				this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
			},
			// 用户协议
			handleUserAgrement() {
				let site = this.globalConfig.appInfo.agreements[1]
				this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
			},
			// 获取图形验证码
			getCode() {
				getCodeImg().then(res => {
					this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
					if (this.captchaEnabled) {
						this.codeUrl = 'data:image/gif;base64,' + res.img
						this.loginForm.uuid = res.uuid
					}
				})
			},
			getData() {
				// console.log("sssssssss");
				getListData().then(res => {
					console.log(JSON.stringify(res));
					this.listData = res.data;
				})
			},
			// 登录方法
			async handleLogin() {
				if (this.loginForm.username === "") {
					this.$modal.msgError("请输入您的账号")
				} else if (this.loginForm.password === "") {
					this.$modal.msgError("请输入您的密码")
				} else if (this.loginForm.code === "" && this.captchaEnabled) {
					this.$modal.msgError("请输入验证码")
				} else {
					this.$modal.loading("登录中，请耐心等待...")
					this.pwdLogin()
				}
			},
			// 密码登录
			async pwdLogin() {
				this.$store.dispatch('Login', this.loginForm).then(() => {
					this.$modal.closeLoading()
					this.loginSuccess()
				}).catch(() => {
					if (this.captchaEnabled) {
						this.getCode()
					}
				})
			},
			// 登录成功后，处理函数
			loginSuccess(result) {
				// 设置用户信息
				this.$store.dispatch('GetInfo').then(res => {
					this.$tab.reLaunch('/pages/index')
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.cover-image {
		flex: 1;
		height: 200rpx;
		width: 200rpx;
	}

	.slide-image {
		width: 100%;
		height: 390rpx;
	}
</style>